package fmppc.scanner;

import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;

import java.util.Set;

/**
 * 类描述: 谋略类路径扫描器
 * <br />
 * 不能使用@Configuration注解，使用此注解只会注入为普通的对象；不会起到实际的作用
 * 要使用@Import方式加入进来或者实现ImportBeanDefinitionRegistrar来进行加载
 *
 * @author : 王雷
 * @date : 2020/7/14 0014 下午 8:54
 */
@Slf4j
public class MyBatisEnhanceBeanScanner extends ClassPathBeanDefinitionScanner {

    /**
     * Create a new {@code ClassPathBeanDefinitionScanner} for the given bean factory.
     *
     * @param registry the {@code BeanFactory} to load bean definitions into, in the form
     *                 of a {@code BeanDefinitionRegistry}
     */
    public MyBatisEnhanceBeanScanner(BeanDefinitionRegistry registry) {
        super(registry);
    }

    /**
     * Configures parent scanner to search for the right interfaces. It can search
     * for all interfaces or just for those that extends a markerInterface or/and
     * those annotated with the annotationClass
     */
    public void registerFilters() {
//        addIncludeFilter(new AssignableTypeFilter(IStrategyBusinessProcess.class) {
//            @Override
//            protected Boolean matchSuperClass(@NotNull String superClassName) {
//                log.info("过滤器org.springframework.core.type.filter.AssignableTypeFilter.matchSuperClass获取到的参数为：{}", superClassName);
//                return AbstractStrategyBusinessProcess.class.getName().equals(superClassName);
//            }
//
//            @Override
//            protected Boolean matchInterface(@NotNull String interfaceName) {
//                log.info("过滤器org.springframework.core.type.filter.AssignableTypeFilter.matchInterface获取到的参数为：{}", interfaceName);
//                return IStrategyBusinessProcess.class.getName().equals(interfaceName);
//            }
//        });
    }

    @NotNull
    @Override
    public Set<BeanDefinitionHolder> doScan(@NotNull String... basePackages) {
        return super.doScan(basePackages);
        /*Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

        if (beanDefinitions.isEmpty()) {
            log.info("在参数：{}；中没有发现任何满足要求的：{}", basePackages, IStrategyBusinessProcess.class);
        } else {
            processBeanDefinitions(beanDefinitions);
        }

        return beanDefinitions;*/
    }
}
